package com.cc.blog.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cc.blog.admin.convert.BlogSettingsConvert;
import com.cc.blog.admin.domain.dto.UpdateBlogSettingsReqDTO;
import com.cc.blog.admin.domain.vo.FindBlogSettingsRspVO;
import com.cc.blog.admin.mapper.BlogSettingsMapper;
import com.cc.blog.admin.model.BlogSettingsDO;
import com.cc.blog.admin.service.AdminBlogSettingsService;
import com.cc.blog.common.utils.Result;
import org.springframework.stereotype.Service;

/**
 * @Author cc
 * @Date 2024/7/11 10:08
 */
@Service
public class AdminBlogSettingsServiceImpl extends ServiceImpl<BlogSettingsMapper, BlogSettingsDO> implements AdminBlogSettingsService {
    @Override
    public Result updateBlogSettings(UpdateBlogSettingsReqDTO updateBlogSettingsReqDTO) {
        // DTO 转 DO
        BlogSettingsDO blogSettingsDO = BlogSettingsConvert.INSTANCE.convertDTO2DO(updateBlogSettingsReqDTO);
        blogSettingsDO.setId(1L);
        // 保存或更新（当数据库中存在 ID 为 1 的记录时，则执行更新操作，否则执行插入操作）
        saveOrUpdate(blogSettingsDO);
        return Result.success();
    }

    @Override
    public Result findDetail() {
        // 查询 ID 为 1 的记录
        BlogSettingsDO blogSettingsDO = getById(1L);
        // DO 转 VO
        FindBlogSettingsRspVO vo = BlogSettingsConvert.INSTANCE.convertDO2VO(blogSettingsDO);
        return Result.success(vo);
    }
}
